package com.springmvc.core;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ScanSubPackege {
	public static String pakeagePath = null;
	
	public ScanSubPackege(){
		pakeagePath = this.getClass().getResource("/").getPath();
	}
	
	//扫描子包下的类名
	public ArrayList<String> scan(String path){
		String[] split = path.split("\\.");
		for (String string : split) {
			pakeagePath = pakeagePath+File.separator+string;
		}
		File file = new File(pakeagePath);
		return findPackage(file);
	}
	
	private ArrayList<String> findPackage(File file){
		ArrayList<String> arrayList = new ArrayList<>();
		File[] listFiles = file.listFiles();
		for (File file2 : listFiles) {
			if(file2.exists()){
				if(file2.getName().endsWith("class")){
					String substring = file2.getName().substring(0,file2.getName().lastIndexOf("."));
					arrayList.add(substring);
				}
			}
		}
		
		return arrayList;
	}
	//
	public static void main(String[] args) {
		ScanSubPackege scanSubPackege = new ScanSubPackege();
		List<String> scan = scanSubPackege.scan("com.springmvc.controller");
		for (String string : scan) {
			System.out.println(string);
		}
		
	}
}
